<template>
    <view class="cn-account">
        <custom><template #backText>注册</template></custom>
        <view class="flex justify-center">
            <image class="cn-logo" src="/static/image/logo/122x122.png"></image>
        </view>
        <view class="padding-lr-30">
            <nFormItem icon='cuIcon-people' placeholder="手机号 / 账号" :data.sync="data" field="phone"></nFormItem>
            <nFormItem icon='cuIcon-command' placeholder="登录密码" :data.sync="data" field="password_md5" :password="true"></nFormItem>
            <nFormItem icon='cuIcon-like' placeholder="邀请码" format="number" :data.sync="data" field="parent_id" :disabled="lock_parent_id">
                <template #left v-if="lock_parent_id">
                    <view class="title min-width-em3">邀请码</view>
                </template>
            </nFormItem>
            <nFormButton title="注册" :tap="register"></nFormButton>
            <view class="margin-lr-30 flex justify-between text-999">
                <view @tap="$store.commit('userNavTo', '/account/login')">已有账号，去登录</view>
            </view>
        </view>
        <a v-if="app_type == 0" :href="'https://zy-jdc.oss-cn-hangzhou.aliyuncs.com/apk/joa-'+version_no+'.apk'" target='_blank'>
            <foot title="下载安卓版"></foot>
        </a>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                data: {
                    formtag: {},
                    form: {
                        phone: '',
                        password_md5: '',
                        parent_id: ''
                    },
                },
                lock_parent_id: false,
                app_type: this.$app.app_type,
                version_no: this.$app.version_no,
            }
        },
        onLoad(params) {
            if (params.pid && !isNaN(params.pid)) {
                this.data.form.parent_id = params.pid;
                this.lock_parent_id = true;
            }
        },
        methods: {
            register() {
                this.$api.post(this, {
                    loading: '注册中',
                    url: '/account/register/phonePassword',
                    success: (Result) => {
                        if (this.$api.form.toast(this, Result)) return;
                        this.$store.commit('userLogin', Result.result);
                    }
                });
            }
        }
    }
</script>

<style lang="less">
    @import "./account.less";
</style>
